package com.newer.his.common.mapper;


import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import com.newer.his.common.entity.Dept;


@Mapper
public interface DeptMapper {
	
	@Options(useGeneratedKeys = true, 
			keyColumn = "dept_id", 
			keyProperty = "id")
	@Insert("insert into dept( name, updept, `rank`)"
			+ " values(#{name},#{updept},#{rank})")
	void save(Dept dept);
	
	@Result(property = "id" ,column = "dept_id")
	@Select("select dept_id, name, updept, `rank` from dept"
			+ " where dept_id=#{id}")
	Dept findbyId(int id);
	
	
	@Result(property = "id" ,column = "dept_id")
	@Select("select dept_id, name, updept, `rank` from dept")
	List<Dept> findAll();
	
	
	@Update("update dept set name=#{name}, updept=#{updept}, `rank`={rank}"
			+ " where  dept_id=#{id}")
	void update (Dept dept);
	
	
	@Delete("delete from dept where dept_id=#{id}")
	void delete(int id);

	// 通过科室名找科室对象
	//	字段	类型	是否空	默认值	键	描述
	//	id	int	非空		主键	主键
	//	name	varchar(50)	空	NULL		科室名
	//	updept	int	空	NULL		上级科室
	//	rank	Varchar（45）	空	NULL		级别
	
//	private int id;
//	private String name; 
//	private int updept;
//	private String rank;
	@Select("select dept_id,`name`,`updept`,`rank` from dept where dept_id=#{id};")
	@Results(
			id="",
			value= {
					@Result(column = "dept_id",property = "id"),
					@Result(column = "name",property = "name"),
					@Result(column = "updept",property = "updept"),
					@Result(column = "rank",property = "rank"),
				}
			)
	Dept Byid(int id);
}
